package com.hotspot.chartview.view.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

import com.hotspot.chartview.R;
import com.hotspot.chartview.model.BarChartData;
import com.hotspot.chartview.model.ColoredBarChartData;
import com.hotspot.chartview.model.FunnelChartData;
import com.hotspot.chartview.model.LineChartData;
import com.hotspot.chartview.view.BarChart;
import com.hotspot.chartview.view.BarChart.BarChartListener;
import com.hotspot.chartview.view.ColoredBarChart;
import com.hotspot.chartview.view.FunnelChart;
import com.hotspot.chartview.view.LineChart;
import com.hotspot.chartview.view.ProgressText;

public class MainActivity extends Activity implements BarChartListener {

    private static final String TAG = "MainActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        /**
         * 自定义进度条
         */
        ProgressText progressText = (ProgressText) findViewById(R.id.progress_text);
        progressText.setProgress(80);
        progressText.startAnimation(2000);

        /**
         * 折线图
         */
        LineChart lineChart = (LineChart) findViewById(R.id.line_chart);
        List<LineChartData> lineChartDatas = new ArrayList<LineChartData>();
        for (int i = 0; i < 7; i++) {
            Random random = new Random();
            LineChartData lineChartData = new LineChartData(i, "12/1" + i, "周" + i,
                    random.nextInt(500));
            lineChartDatas.add(lineChartData);
        }
        lineChart.setLineChartData(lineChartDatas);
        lineChart.animateY(3000);

        /**
         * 分颜色的柱状图
         */
        ColoredBarChart coloredBarChart = (ColoredBarChart) findViewById(R.id.colored_bar_chart);
        List<ColoredBarChartData> coloredBarChartDatas = new ArrayList<ColoredBarChartData>();
        for (int i = 0; i < 7; i++) {
            Random random = new Random();
            ColoredBarChartData coloredBarChartData = new ColoredBarChartData(i, "类别" + i,
                    getResources().getColor(R.color.colored_bar_chart_bar_color_default),
                    random.nextInt(500));
            coloredBarChartDatas.add(coloredBarChartData);
        }
        coloredBarChart.setColoredBarChartData(coloredBarChartDatas);
        coloredBarChart.animateY(3000);

        /**
         * 普通柱状图
         */
        BarChart barChart = (BarChart) findViewById(R.id.barchart);
        List<BarChartData> barChartDatas = new ArrayList<BarChartData>();
        Random random = new Random();
        for (int i = 0; i < 30; i++) {
            barChartDatas.add(new BarChartData(i, "测试数据" + i, random.nextInt(400)));
        }
        barChart.setBarChartData(barChartDatas);
        barChart.setBarChartListener(this);

        /**
         * 漏斗图
         */
        FunnelChart funnelChart = (FunnelChart) findViewById(R.id.funnel_chart);
        List<FunnelChartData> funnelChartDatas = new ArrayList<FunnelChartData>();
        for (int i = 4; i > 0; i--) {
            funnelChartDatas.add(new FunnelChartData(i, "测试数据" + i, i * 100));
        }
        funnelChart.setFunnelChartData(funnelChartDatas);
        funnelChart.animateX(3000);
    }

    @Override
    public void onCenterViewChanged(BarChartData gridViewData) {
        Log.i(TAG, "gridViewData = " + gridViewData.title);
    }

}
